<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class LinkController extends Controller
{
    
    
    
    //已预约
    public function index(Request $request)
    {
         $db = \DB::table("link");
        //判断并封装搜索条件
        $where = [];
        if($request->has("keyword")){
            $kw = $request->input("keyword");
            $db->where("name","like","%{$kw}%")->orwhere("phone","like","%{$kw}%");
            $where['keyword'] = $kw;
        }
       
        
        $list = $db
                ->select('link.*','product.pro_name','allusers.nickName')
                ->leftJoin('product', 'link.pro_id', '=', 'product.id')
                ->leftJoin('allusers', 'link.openid', '=', 'allusers.openid')
                ->where('link.status',0)->paginate(5); //获取所有信息
      
        return view("admin.link.yuyue",["list"=>$list,"where"=>$where]);
    }
    
    
    
    public  function  sorry()
    {
         $id = request('id');
         
         $info =  \DB::table('link')
            ->where('id',$id)
            ->update(['status' => 2]);
            
            
            if($info){
                   $msg = array(
                        'status' =>200,
                        'message'=>'确认逾期成功',
                    );
                 return $msg;
            }else{
                   $msg = array(
                        'status' =>000,
                        'message'=>'确认逾期失败',
                    );
                 return $msg;
            }
            
    }
      /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $info =  \DB::table('link')
            ->where('id',$id)
            ->update(['is_del' => 1]);
    
            if($info){
                 return redirect("link")->with("err","完成预约成功！");
            }else{
                 return redirect("link")->with("err","完成预约失败！");
            }
    }
    
   
    
    
}
